﻿using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Terraria.Achievements;

namespace Terraria.GameContent.Achievements
{
	// Token: 0x02000467 RID: 1127
	public class CustomFloatCondition : AchievementCondition
	{
		// Token: 0x170002A9 RID: 681
		// (get) Token: 0x06002653 RID: 9811 RVA: 0x0001A9CA File Offset: 0x00018BCA
		// (set) Token: 0x06002654 RID: 9812 RVA: 0x004918BC File Offset: 0x0048FABC
		public float Value
		{
			get
			{
				return this._value;
			}
			set
			{
				float num = Utils.Clamp<float>(value, 0f, this._maxValue);
				if (this._tracker != null)
				{
					((ConditionFloatTracker)this._tracker).SetValue(num, true);
				}
				this._value = num;
				if (this._value == this._maxValue)
				{
					this.Complete();
				}
			}
		}

		// Token: 0x06002655 RID: 9813 RVA: 0x0001A9D2 File Offset: 0x00018BD2
		private CustomFloatCondition(string name, float maxValue) : base(name)
		{
			this._maxValue = maxValue;
			this._value = 0f;
		}

		// Token: 0x06002656 RID: 9814 RVA: 0x0001A9ED File Offset: 0x00018BED
		public override void Clear()
		{
			this._value = 0f;
			base.Clear();
		}

		// Token: 0x06002657 RID: 9815 RVA: 0x0001AA00 File Offset: 0x00018C00
		public override void Load(JObject state)
		{
			base.Load(state);
			this._value = (float)state["Value"];
			if (this._tracker != null)
			{
				((ConditionFloatTracker)this._tracker).SetValue(this._value, false);
			}
		}

		// Token: 0x06002658 RID: 9816 RVA: 0x0001AA3F File Offset: 0x00018C3F
		protected override IAchievementTracker CreateAchievementTracker()
		{
			return new ConditionFloatTracker(this._maxValue);
		}

		// Token: 0x06002659 RID: 9817 RVA: 0x0001AA4C File Offset: 0x00018C4C
		public static AchievementCondition Create(string name, float maxValue)
		{
			return new CustomFloatCondition(name, maxValue);
		}

		// Token: 0x04004199 RID: 16793
		[JsonProperty("Value")]
		private float _value;

		// Token: 0x0400419A RID: 16794
		private float _maxValue;
	}
}
